local CURSOR_OVER_WORLD = "Mouse cursor must be over the desired frame.";
local NOT_REGISTERED = "Frame is not registered for fading (use |cFF33FF99/kong hide|r first).";
local ALREADY_REGISTERED = "Frame is already registered for fading.";
local CANNOT_SAVE = "Settings for this frame cannot be saved between game sessions.";
local FRAME_ADDED = "Frame registered.";
local FRAME_REMOVED = "Frame unregistered.";
local ALPHA_REQUIRED = "Alpha required (ex: |cFF33FF99/kong %s alpha .6|r)."
local BAD_ALPHA = "Alpha must be between 0 (transparent) and 1 (opaque).";
local ALPHA_SET = "Alpha set.";
local SPEED_REQUIRED = "Speed required (ex: |cFF33FF99/kong %s speed in .2|r)."
local SPEED_IN_OR_OUT = "\"in\" or \"out\" required (ex: |cFF33FF99/kong %s speed in .2|r).";
local BAD_SPEED = "Speed must be 0 or greater."
local SPEED_SET = "Speed set.";
local TRIGGER_CONDITION = {
    ["combat"] = "during combat",
    ["nocombat"] = "out of combat",
    ["vehicle"] = "when in a vehicle",
    ["novehicle"] = "when not in a vehicle",
    ["casting"] = "while casting",
    ["nocasting"] = "while not casting",
    ["macro"] =  "when the given condition is true",
    ["mouseover"] = "when moused-over",
};
local HELP_TRIGGER_COMMANDS = "|cFFBBBBFFKong Automatic UI Hider|r %s commands ( |cFF33FF99/kong %s|r ):";
local HELP_TRIGGER_SHOW = "|cFF33FF99show|r: configures the frame to fade in %s.";
local HELP_TRIGGER_HIDE = "|cFF33FF99hide|r: configures the frame to remain hidden %s.";
local HELP_TRIGGER_ALPHA = "|cFF33FF99alpha <alpha>|r: sets the alpha (transparency) to use %s.";
local HELP_TRIGGER_SPEED = "|cFF33FF99speed <in||out> <seconds>|r: sets the duration in seconds over which this trigger fades the frame in or out.";
local TRIGGER_NOT_REGISTERED = "Trigger %q has not been configured for use with this frame (use |cFF33FF99/kong %s|r first).";
local UNKNOWN_OPTION = "Unknown option: %q (Type |cFF33FF99/kong %s|r for help).";
local BOOLEAN_SUCCESS = {
    ["show"] = "Frame will now appear %s.",
    ["hide"] = "Frame will now remain hidden %s.",
};
local HELP_MACRO_GET = "|cFF33FF99get|r: displays the current macro condition (if any).";
local HELP_MACRO_SET = "|cFF33FF99set <condition>|r: configures the frame to fade in when the given macro condition evaluates to true. "
                     .."(ie: |cFF33FF99/kong macro set [exists]|r will make the frame fade in when you have a target selected.)";
local HELP_MACRO_CLEAR = "|cFF33FF99clear|r: clears the current macro condition.";
local MACRO_APPLIED = "Frame will now be shown when the condition %q is met.";
local MACRO_REMOVED = "Macro condition cleared.";
local CURRENT_MACRO = "Current macro condition for this frame is %q.";
local NO_CURRENT_MACRO = "No current macro condition for this frame.";
local CONDITION_REQUIRED = "Macro condition required (ex: |cFF33FF99/kong macro set [mounted]|r ).";
local INVALID_CONDITION = "Invalid macro condition %q (ex: |cFF33FF99/kong macro set [mounted]|r ).";
local GROUP_NAME_NEEDED = "Group name must be specified (ex: |cFF33FF99/kong group %s group1|r)."
local GROUP_ADD = "Frame added to group: %q";
local GROUP_REMOVE = "Frame removed from group: %q";
local FRAME_ALREADY_IN_GROUP = "Frame is already a member of group: %q";
local FRAME_NOT_IN_GROUP = "Frame is not currently in group: %q";
local NO_SUCH_GROUP = "There is no group named %q.";
local HELP_GROUP_ADD = "|cFF33FF99add <name>|r: adds a frame to a named mouseover group. All frames "
                     .."in this group will be shown whenever any frame in the group is moused-over.";
local HELP_GROUP_REMOVE = "|cFF33FF99remove <name>|r: removes a frame from the specified mouseover group.";
local HELP_GROUP_LIST = "|cFF33FF99list|r: lists the groups that a frame is a member of.";
local ALPHA_IN_OR_OUT = "\"in\" or \"out\" required (ex: |cFF33FF99/kong alpha in .2|r).";
local PROFILE_NAME_REQUIRED = "Profile name required.";
local NO_SUCH_PROFILE = "Profile %q does not exist. Use |cFF33FF99/kong profile list|r to see a list of available profiles.";
local PROFILE_LOADED = "Profile %q loaded.";
local NOW_USING_PROFILE = "Now using profile %q.";
local PROFILE_ALREADY_EXISTS = "Profile %q already exists.";
local CANNOT_DELETE_CURRENT_PROFILE = "Cannot delete current profile.";
local PROFILE_ALREADY_LOADED = "Profile %q is already the current profile.";
local PROFILE_DELETED = "Profile %q deleted.";
local PROFILE_RESET = "Current profile %q has been reset.";
local HELP_PROFILE_COMMANDS = "|cFFBBBBFFKong Automatic UI Hider|r profile commands ( |cFF33FF99/kong profile|r ):";
local HELP_PROFILE_LOAD = "|cFF33FF99load <name>|r: loads the specified profile.";
local HELP_PROFILE_CREATE = "|cFF33FF99create <name>|r: creates a new profile with the given name.";
local HELP_PROFILE_DELETE = "|cFF33FF99delete <name>|r: deletes the specified profile.";
local HELP_PROFILE_LIST = "|cFF33FF99list|r: lists all available profiles.";
local HELP_PROFILE_CURRENT = "|cFF33FF99current|r: prints the current profile name.";
local FRAME_LIST = "Frames registered for fading:";
local INVALID_COMMAND = " command unknown (Type |cFF33FF99/kong help|r for help)."
local NO_KONG_CONFIG = "Kong Config is either disabled or not installed. Defaulting to command-line interface..."
local HELP_COMMANDS = "|cFFBBBBFFKong Automatic UI Hider|r commands ( |cFF33FF99/kong|r ):";
local HELP_HIDE = "|cFF33FF99hide|r: registers a frame to be faded out when not in use.";
local HELP_SHOW = "|cFF33FF99show|r: unregisters a frame, causing it to be permanently shown.";
local HELP_COMBAT = "|cFF33FF99combat|r: configures the way a frame behaves when in combat.";
local HELP_NOCOMBAT = "|cFF33FF99nocombat|r: configures the way a frame behaves when not in combat.";
local HELP_VEHICLE = "|cFF33FF99vehicle|r: configures the way a frame behaves when in a vehicle.";
local HELP_CASTING = "|cFF33FF99casting|r: configures the way a frame behaves when in a casting.";
local HELP_MOUSEOVER = "|cFF33FF99mouseover|r: configures the way a frame behaves when the mouse cursor is over it.";
local HELP_GROUP = "|cFF33FF99group|r: configures multiple frames to appear when a single frame is moused-over.";
local HELP_MACRO = "|cFF33FF99macro|r: configures the way a frame behaves when the result of a user-specified macro condition changes.";
local HELP_ALPHA = "|cFF33FF99alpha <in||out>|r: sets the default alpha (transparency) to use when fading a frame in or out.";
local HELP_SPEED = "|cFF33FF99speed <in||out> <seconds>|r: sets the default duration in seconds over which a frame fades in or out.";
local HELP_LIST = "|cFF33FF99list|r: lists each frame (or children of unnamed frames) currently registered for fading.";
local HELP_TOGGLE = "|cFF33FF99enable / disable / toggle|r: enables or disables fading of the user interface.";
local HELP_PROFILE = "|cFF33FF99profile|r: manages saved Kong configurations and allows for configuration sharing between characters.";

local ENABLED = "Enabled.";
local ALREADY_ENABLED = "Already enabled."
local DISABLED = "Disabled.";
local ALREADY_DISABLED = "Already disabled.";

function Kong_GetRoot(Frame)

    local Parent = Frame;
    while Parent and Parent ~= UIParent do
        Frame = Parent;
        Parent = Frame:GetParent();
    end

    return Frame;
end

function Kong_SingleFrameCommandHandler(Handler, ...)

    local Focus = GetMouseFocus();
    if Focus == WorldFrame or Focus == UIParent then
        Kong_Error(CURSOR_OVER_WORLD);
        return;
    end
    local Root = Kong_GetRoot(Focus);
    if Kong_Frames[Root] then
        Handler(Root, ...);
    else
        Kong_Error(NOT_REGISTERED);
    end
end

function Kong_HideCommandHandler()

    local Focus = GetMouseFocus();
    if Focus == WorldFrame or Focus == UIParent then
        Kong_Error(CURSOR_OVER_WORLD);
        return;
    end

    local Root = Kong_GetRoot(Focus);
    if not Kong_Frames[Root] then
        
        Kong_RegisterFrame(Root)
        if Kong_Settings.enabled then
            Kong_FadeIn(Root, Kong_Frames[Root].mouseover);
        end
        Kong_Info(FRAME_ADDED);

    else
        Kong_Error(ALREADY_REGISTERED);
    end
end

function Kong_ShowCommandHandler(Root, args)
    -- For any groups that this frame was part of
    for groupName,Group in pairs(Kong_Settings.Groups) do 
        if Group[Kong_Frames[Root].index] then
        
            -- Fade out the group
            for _,GroupFrame in pairs(Group) do
                Kong_FadeOut(GroupFrame, Kong_Frames[GroupFrame].mouseover);
            end
        end
    end
    Kong_UnregisterFrame(Root)
end

function Kong_BooleanCommandHandler(Root, args)

    local triggerName = args[1];
    local option = args[2];

    if not option then
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_COMMANDS, triggerName, triggerName));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_SHOW, TRIGGER_CONDITION[triggerName]));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_HIDE, TRIGGER_CONDITION[triggerName]));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_ALPHA, TRIGGER_CONDITION[triggerName]));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_SPEED, TRIGGER_CONDITION[triggerName]));
    
    elseif option == "show" then

        Kong_SetFrameBooleanVisibility(Root, triggerName, true);
        Kong_Info(BOOLEAN_SUCCESS[option], TRIGGER_CONDITION[triggerName]);

    elseif option == "hide" then

        Kong_SetFrameBooleanVisibility(Root, triggerName, false);
        Kong_Info(BOOLEAN_SUCCESS[option], TRIGGER_CONDITION[triggerName]);

    elseif option == "alpha" or option == "speed" then

        Kong_AlphaAndSpeedOptionHandler(Root, args);

    else

        Kong_Error(UNKNOWN_OPTION, option, triggerName);
    end
end

function Kong_MacroCommandHandler(Root, args)

    local triggerName = args[1];
    local option = args[2];

    if not option then
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_COMMANDS, triggerName, triggerName));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_MACRO_GET));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_MACRO_SET));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_MACRO_CLEAR));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_ALPHA, TRIGGER_CONDITION[triggerName]));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_SPEED, TRIGGER_CONDITION[triggerName]));
    
    elseif option == "set" then

        if (2 < #args) then

            input = table.concat(args, " ", 3)
            
            if Kong_SetMacro(Root, input) then
                Kong_Info(MACRO_APPLIED, Kong_Frames[Root].macro.condition);
            else
                Kong_Error(INVALID_CONDITION, input);
            end
        else
            Kong_Error(CONDITION_REQUIRED);
            return;
        end

    elseif option == "clear" then

        Kong_ClearMacro(Root);
        Kong_Info(MACRO_REMOVED);

    elseif option == "get" then

        if Kong_Frames[Root].macro then
            Kong_Info(CURRENT_MACRO, Kong_Frames[Root].macro.condition);
        else
            Kong_Info(NO_CURRENT_MACRO);
        end

    elseif option == "alpha" or option == "speed" then

        Kong_AlphaAndSpeedOptionHandler(Root, args);

    elseif option and option ~= "" then

        Kong_Error(UNKNOWN_OPTION, option, triggerName);
    end
end

function Kong_MouseoverCommandHandler(Root, args)

    local triggerName = args[1];
    local option = args[2];

    if not option then
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_COMMANDS, triggerName, triggerName));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_ALPHA, TRIGGER_CONDITION[triggerName]));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_SPEED, TRIGGER_CONDITION[triggerName]));
    
    elseif option == "alpha" or option == "speed" then

        Kong_AlphaAndSpeedOptionHandler(Root, args);

    else
        Kong_Error(UNKNOWN_OPTION, option, triggerName);
    end
end

function Kong_MouseoverGroupCommandHandler(Root, args) 

    local command = args[2];
    local name = table.concat(args, " ", 3);

    if not command then
    
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_TRIGGER_COMMANDS, args[1], args[1]));
        DEFAULT_CHAT_FRAME:AddMessage(HELP_GROUP_ADD);
        DEFAULT_CHAT_FRAME:AddMessage(HELP_GROUP_REMOVE);
        DEFAULT_CHAT_FRAME:AddMessage(HELP_GROUP_LIST);
    
    elseif command == "add" then
        if name and not (name == "") then
            if Kong_AddFrameToGroup(Root, name) then
                
                -- Fade in the group
                for _,GroupFrame in pairs(Kong_Settings.Groups[name]) do
                    Kong_FadeIn(GroupFrame, Kong_Frames[GroupFrame].mouseover);
                end
                
                Kong_Info(GROUP_ADD, name);
            else
                Kong_Error(FRAME_ALREADY_IN_GROUP, name);
            end
        else
            Kong_Error(GROUP_NAME_NEEDED, command);
        end
    elseif command == "remove" then
        if name and not (name == "") then
            local Group = Kong_Settings.Groups[name];
            if Group then
                if Group[Kong_Frames[Root].index] then
                
                    -- Fade out the group
                    for _,GroupFrame in pairs(Group) do
                        Kong_FadeOut(GroupFrame, Kong_Frames[GroupFrame].mouseover);
                    end
                    
                    if Kong_RemoveFrameFromGroup(Root, name) then
                        Kong_Info(GROUP_REMOVE, name);
                    end
                else
                    Kong_Error(FRAME_NOT_IN_GROUP, name);
                end
            else
                Kong_Error(NO_SUCH_GROUP, name);
            end
        else
            Kong_Error(GROUP_NAME_NEEDED, command);
        end
    elseif command == "list" then
        local GroupNames = {};
        for groupName,Group in pairs(Kong_Settings.Groups) do
            if Group[Kong_Frames[Root].index] then
                tinsert(GroupNames, groupName);
            end
        end
        if next(GroupNames) then
            Kong_Info("Frame is a member of groups: "..table.concat(GroupNames, ", "));
        else
            Kong_Info("Frame is not a member of any groups");
        end
    else
        Kong_Error(UNKNOWN_OPTION, command, args[1]);
    end
end 
      
function Kong_AlphaCommandHandler(Root, args)

    local direction;
    if args[2] == "in" then
        direction = "alphaIn";
    elseif args[2] == "out" then
        direction = "alphaOut";
    else
        Kong_Error(ALPHA_IN_OR_OUT, option);
        return;
    end

    local alpha;
    if args[3] then
        alpha = tonumber(args[3]);
        if alpha and alpha >= 0 and alpha <= 1 then
            Kong_Frames[Root].TriggerDefaults[direction] = alpha;

            Kong_Info(ALPHA_SET);
        else
            Kong_Error(BAD_ALPHA);
        end
    else
        Kong_Error(ALPHA_REQUIRED, "");
    end
end

function Kong_SpeedCommandHanlder(Root, args)

    local direction, seconds = args[2], args[3];

    if direction == "in" then
        direction = "secondsIn";
    elseif direction == "out" then
        direction = "secondsOut";
    else
        Kong_Error(SPEED_IN_OR_OUT, "");
        return;
    end

    if seconds then
        seconds = tonumber(seconds);
        if seconds and seconds >= 0 then
            Kong_Frames[Root].TriggerDefaults[direction] = seconds;
            Kong_Info(SPEED_SET);
        else
            Kong_Error(BAD_SPEED);
        end
    else
        Kong_Error(SPEED_REQUIRED, "");
    end
end

function Kong_ProfileCommandHandler(args)

    operation = args[2];
    profile = table.concat(args, "_", 3);
    
    if not operation then
    
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_PROFILE_COMMANDS));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_PROFILE_LOAD));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_PROFILE_CREATE));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_PROFILE_DELETE));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_PROFILE_LIST));
        DEFAULT_CHAT_FRAME:AddMessage(string.format(HELP_PROFILE_CURRENT));
    
    elseif operation == "load" then
    
        if profile then
            if Kong_Profiles[profile] then
                if profile ~= Kong_Settings.profile then
                
                    Kong_Unload();
                    Kong_Settings.profile = profile;
                    Kong_LoadSettings();
                    
                    Kong_Info(PROFILE_LOADED, profile);
                else
                    Kong_Error(PROFILE_ALREADY_LOADED, profile);
                end
            else
                Kong_Error(NO_SUCH_PROFILE, profile);
            end
        else
            Kong_Error(PROFILE_NAME_REQUIRED);
        end
    elseif operation == "create" then
    
        if profile then
            if not Kong_Profiles[profile] then
            
                Kong_Unload();
                Kong_Settings.profile = profile;
                Kong_LoadSettings();
                
                Kong_Info(NOW_USING_PROFILE, profile);
            else 
                Kong_Error(PROFILE_ALREADY_EXISTS, profile);
            end
        else
            Kong_Error(PROFILE_NAME_REQUIRED);
        end
    elseif operation == "list" then
        local ProfileNames = {};
        for name in pairs(Kong_Profiles) do
            tinsert(ProfileNames, name);
        end
        Kong_Info("Available profiles: "..table.concat(ProfileNames, ", "));
        
    elseif operation == "current" then
    
        Kong_Info("Current profile is: "..Kong_Settings.profile);
        
    elseif operation == "delete" then
    
        if profile then
            if profile ~= Kong_Settings.profile then
                if Kong_Profiles[profile] then
                    Kong_Profiles[profile] = nil;
                    Kong_Info(PROFILE_DELETED, profile);
                else
                    Kong_Error(NO_SUCH_PROFILE, profile);
                end
            else
                Kong_Error(CANNOT_DELETE_CURRENT_PROFILE);
            end
        else
            Kong_Error(PROFILE_NAME_REQUIRED);
        end
    else
        Kong_Error(UNKNOWN_OPTION, operation, args[1]);
    end
end

function Kong_ResetCommandHandler()
    StaticPopupDialogs["KONG_RESET"] = {
        text = "Are you sure you want to delete all settings from the Kong profile \""..Kong_Settings.profile.."\"?",
        button1 = "Reset",
        button2 = "Cancel",
        OnAccept = function(self)
        
            Kong_Unload();
            Kong_Profiles[Kong_Settings.profile] = nil
            Kong_LoadSettings();
            
            Kong_Info(PROFILE_RESET, Kong_Settings.profile);
        end,
        showAlert = 1,
        timeout = 0,
        exclusive = nil,
        hideOnEscape = 1
    }
    StaticPopup_Show("KONG_RESET")
end

function Kong_AlphaAndSpeedOptionHandler(Root, args)

    local triggerName = args[1];
    local option = args[2];

    if not Kong_Frames[Root][triggerName] then

        Kong_Error(TRIGGER_NOT_REGISTERED, triggerName, triggerName);

    elseif option == "alpha" then

        if args[3] then
            local alpha = tonumber(args[3]);
            if alpha and alpha >= 0 and alpha <= 1 then
                Kong_Frames[Root][triggerName].alphaIn = alpha
                Kong_Info(ALPHA_SET);
            else
                Kong_Error(BAD_ALPHA);
            end
        else
            Kong_Error(ALPHA_REQUIRED, triggerName);
        end

    elseif option == "speed" then

        local direction;
        if args[3] == "in" then
            direction = "secondsIn";
        elseif args[3] == "out" then
            direction = "secondsOut";
        else
            Kong_Error(SPEED_IN_OR_OUT, triggerName);
            return;
        end

        if args[4] then
            local seconds = tonumber(args[4]);
            if seconds and seconds >= 0 then
                Kong_Frames[Root][triggerName][direction] = seconds;
                Kong_Info(SPEED_SET);
            else
                Kong_Error(BAD_SPEED);
            end
        else
            Kong_Error(SPEED_REQUIRED, option);
        end
    end
end

function Kong_EnableCommandHandler()
    if not Kong_Settings.enabled then
        Kong_Enable()
        Kong_Info(ENABLED);
    else
        Kong_Error(ALREADY_ENABLED);
    end
end

function Kong_DisableCommandHandler()
    if Kong_Settings.enabled then
        Kong_Disable()
        Kong_Info(DISABLED);
    else
        Kong_Error(ALREADY_DISABLED);
    end
end

function Kong_ToggleCommandHandler()
    if Kong_Settings.enabled then
        Kong_DisableCommandHandler();
    else
        Kong_EnableCommandHandler();
    end
end

function Kong_List()

    Kong_Info(FRAME_LIST);
    for i in pairs(Kong_Settings.Frames) do
        DEFAULT_CHAT_FRAME:AddMessage(i);
    end
end

function Kong_Debug(Root)
    print("----- "..tostring(Root:GetName()).." -----");
    for _,triggerName in pairs(KONG_TRIGGER_NAMES) do
        local Trigger = Kong_Frames[Root][triggerName];
        if Trigger then
            print(triggerName..".refs: "..tostring(Trigger.refs));
        end
    end
end

function Kong_CommandHandler(args)
    local args = {strsplit(" ", string.lower(args))};
    local command = args[1];

    if command == "hide" or command == "fade" then
        Kong_HideCommandHandler();
    elseif command == "show" then
        Kong_SingleFrameCommandHandler(Kong_ShowCommandHandler);
        Kong_Info(FRAME_REMOVED);
    elseif command == "combat" then
        Kong_SingleFrameCommandHandler(Kong_BooleanCommandHandler, args);
    elseif command == "nocombat" then
        Kong_SingleFrameCommandHandler(Kong_BooleanCommandHandler, args);
    elseif command == "vehicle" then
        Kong_SingleFrameCommandHandler(Kong_BooleanCommandHandler, args);
    elseif command == "novehicle" then
        Kong_SingleFrameCommandHandler(Kong_BooleanCommandHandler, args);
    elseif command == "casting" then
        Kong_SingleFrameCommandHandler(Kong_BooleanCommandHandler, args);
    elseif command == "nocasting" then
        Kong_SingleFrameCommandHandler(Kong_BooleanCommandHandler, args);
    elseif command == "macro" then
        Kong_SingleFrameCommandHandler(Kong_MacroCommandHandler, args);
    elseif command == "mouseover" then
        Kong_SingleFrameCommandHandler(Kong_MouseoverCommandHandler, args);
    elseif command == "group" then
        Kong_SingleFrameCommandHandler(Kong_MouseoverGroupCommandHandler, args);
    elseif command == "alpha" then
        Kong_SingleFrameCommandHandler(Kong_AlphaCommandHandler, args);
    elseif command == "speed" then
        Kong_SingleFrameCommandHandler(Kong_SpeedCommandHanlder, args);
    elseif command == "enable" then
        Kong_EnableCommandHandler();
    elseif command == "disable" then
        Kong_DisableCommandHandler();
    elseif command == "toggle" then
        Kong_ToggleCommandHandler();
    elseif command == "list" then
        Kong_List();
    elseif command == "profile" then
        Kong_ProfileCommandHandler(args);
    elseif command == "reset" then
        Kong_ResetCommandHandler(args)
    elseif command == "debug" then
        Kong_SingleFrameCommandHandler(Kong_Debug, args);
    elseif command and command ~= "" and command ~= "help" then
        Kong_Error("\""..command.."\""..INVALID_COMMAND);
    else
        if command ~= "help" and LoadAddOn('KongConfig') then
            KongConfig_Show()
        else
            if command ~= "help" then
                Kong_Warning(NO_KONG_CONFIG);
            end
            DEFAULT_CHAT_FRAME:AddMessage(HELP_COMMANDS);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_HIDE);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_SHOW);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_COMBAT);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_NOCOMBAT);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_VEHICLE);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_CASTING);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_MACRO);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_MOUSEOVER);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_GROUP);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_ALPHA);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_SPEED);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_LIST);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_TOGGLE);
            DEFAULT_CHAT_FRAME:AddMessage(HELP_PROFILE);
        end
    end
end
SLASH_KONG1 = "/kong";
SlashCmdList["KONG"] = Kong_CommandHandler;
